﻿using Newtonsoft.Json;
using Restaurant.Common;
using Restaurant.Model;
using Restaurant.Site;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;

namespace Restaurant.API.Client.Controllers
{
    /// <summary>
    /// 查询：GET 添加/上传：POST 修改：PUT 删除：DELETE
    /// </summary> 
    public class TableController : ApiController
    {
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="subComanyId"></param>
        /// <returns></returns>
        [ResponseType(typeof(OperationResult))]
        [HttpGet]
        public async Task<HttpResponseMessage> GetAllBySubComanyId(Guid subComanyId)
        {
            TableSite tableSite = new TableSite();

            var fModel = await tableSite.GetAllBySubComanyId(subComanyId);
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StringContent(JsonConvert.SerializeObject(fModel), System.Text.Encoding.UTF8, "application/json"),

            };
            return httpResponseMessage;

        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="table">实体</param>
        /// <returns></returns>
        [ResponseType(typeof(OperationResult))]
        [HttpPost]
        public async Task<HttpResponseMessage> Add(CompanyTable table)
        {
            TableSite tableSite = new TableSite();



            var fModel = await tableSite.AddAsync(table);
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StringContent(JsonConvert.SerializeObject(fModel), System.Text.Encoding.UTF8, "application/json"),

            };
            return httpResponseMessage;

        }
         

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">id标识</param>
        /// <returns></returns>
        [ResponseType(typeof(OperationResult))]
        [HttpDelete]
        public async Task<HttpResponseMessage> Delete(long id)
        {
            TableSite tableSite = new TableSite();

            var fModel = await tableSite.DeleteAsync(id);

            HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StringContent(JsonConvert.SerializeObject(fModel), System.Text.Encoding.UTF8, "application/json"),

            };
            return httpResponseMessage;

        }

    }
}
